iT邦幫忙

2024 iThome 鐵人賽

DAY 1
0
自我挑戰組

opendata 使用 python串接發表系列 第 4

Python3 TQC++ 複習_08/07

  • 分享至 

  • xImage
  •  

203 閏年判斷
methond 1

year = int(input().strip())

if year%400 == 0:
    print("%d is a leap year." %year)
elif year%100 == 0:
    print("%d is not a leap year." %year)
elif year%4 == 0:
    print("%d is a leap year." %year)
else:
    print("%d is not a leap year." %year)

methond 2

year = int(input().strip())

if year%400==0 or (year%4==0 and year%100!=0):
    print("%d is a leap year." %year)
else:
    print("%d is not a leap year." %year)

301 迴圈整數連加

a = int(input().strip())
b = int(input().strip())
total=0
if a>b:
    temp = b
    b = a
    a = temp

for i in range(a,b+1):
    total += i

print(total)

408 奇偶數個數計算

even=odd=0

for i in range(10):
    num = int(input().strip())
    if num%2 == 0:
        even += 1
    else:
        odd += 1

print("Even numbers: %d" %even)
print("Odd numbers: %d" %odd)

參考資料:TQC+ Python 3


上一篇
Python3 TQC++ 複習_08/05
下一篇
Python3 TQC++ 複習 08/12
系列文
opendata 使用 python串接發表13
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言